<!DOCTYPE HTML>
<html>
<head>
    {include file="common/head" /}
</head>
<body>

<article class="Hui-admin-page-container">
    <form class="form form-horizontal" id="form-goods-edit">
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品名称：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$goods.goods_name}" placeholder="" id="goods_name" name="goods_name">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>名称简写：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$goods.goods_simple_name}" placeholder="" id="goods_simple_name" name="goods_simple_name">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>货号：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$goods.goods_sn}" placeholder="" id="goods_sn" name="goods_sn" disabled>
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>条形码：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$goods.goods_code}" placeholder="" id="goods_code" name="goods_code" disabled>
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-2">报价单价格：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$goods.goods_quotation}" placeholder="" id="goods_quotation" name="goods_quotation">
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <input type="hidden" value="{$goods.goods_id}" id="goods_id" name="goods_id">
                <button class="btn btn-primary radius" type="button" id="postdata"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</article>
{include file="common/footer" /}
<script type="text/javascript" src="__ROOT__/static/business/js/main.js"></script>
<script type="text/javascript">
    function validateFrom () {
        return $("#form-goods-edit").validate({
            rules: {
                goods_name: {
                    required:true,
                },
                goods_sn: {
                    required:true,
                },
                goods_code: {
                    required:true,
                },
                goods_simple_name: {
                    required:true,
                }
            },
            messages: {
                goods_name: {
                    required: "商品名称不能为空"
                },
                goods_sn: {
                    required: "货号不能为空"
                },
                goods_code: {
                    required: "条形码不能为空"
                },
                goods_simple_name: {
                    required: "名称简写不能为空"
                },
            },
            onkeyup: false,
            focusCleanup: false,
            submitHandler: function(form) {
                //在这里执行表单提交
                // form.submit();
            }
        }).form();
    }

    $("#postdata").click(function(){
        var goods_name = $("#goods_name").val();
        var goods_sn = $("#goods_sn").val();
        var goods_code = $("#goods_code").val();
        var goods_simple_name = $("#goods_simple_name").val();
        var goods_quotation = $("#goods_quotation").val();
        var goods_id = $("#goods_id").val();
        if(validateFrom()){
            $.ajax({
                url:"{:url('goods/edit')}",
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    goods_name:goods_name,
                    goods_sn:goods_sn,
                    goods_code:goods_code,
                    goods_simple_name:goods_simple_name,
                    goods_quotation:goods_quotation,
                    goods_id:goods_id,
                },
                timeout:5000,
                dataType:'json',
                success:function(data,textStatus,jqXHR){
                    if(data.code==1){
                        layer.alert(data.data.goods_name+data.msg,function(index){
                            parent.location.reload();
                            layer_close();
                        })
                    }else{
                        layer.alert(data.msg)
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误',xhr.responseText)
                }
            })
        }
    });

</script>
</body>
</html>